<?php


namespace App\Extensions\NavBar;


use App\Services\NavbarService;
use Encore\Admin\Facades\Admin;
use Illuminate\Contracts\Support\Renderable;

abstract class AbstractNavBar implements Renderable
{
    abstract function data();

    public function render()
    {
        if (request()->ajax() || request()->pjax()) {
            return '';
        }
        // TODO: Implement render() method.
        $data = $this->data();
        Admin::style($this->style());
        return view('admin.nav-header')->with(compact('data'))->render();
    }

    protected function style()
    {
        return <<<STYLE
 .menu-group-header.on a {
        background: rgba(0, 0, 0, 0.1);
    }
STYLE;

    }

    protected function navbarService(): NavbarService
    {
        return app(NavbarService::class);
    }

    protected function groupData($title, $data): array
    {
        $collect = collect($data);
        return [
            'title'    => $title,
            'count'    => $collect->sum('count'),
            'children' => $collect
        ];
    }

}
